package beans;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.widget.Toast;

import org.json.JSONException;
import org.json.JSONObject;

import config.AppConfig;
import utils.Application;
import utils.SharePHelper;

import static config.AppConfig.DEFAULT_COLOR;

/**
 * Created by zhaoshengping on 2017/2/24.
 */

public class QrMessage {
    private String name;
    private String text;
    private String createTime;
    private String color;
//    private static String DEFAULT_COLOR = "#20000000";

    public QrMessage(String name,String text,String createTime) {
        this.name = name;
        this.text = text;
        this.createTime = createTime;
        this.color = DEFAULT_COLOR;
    }

    public QrMessage(String name,String text,String createTime, String color) {
        this.name = name;
        this.text = text;
        this.createTime = createTime;
        this.color = color;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getCreateTime() {
        return createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }


    public String getColor() {
        return color;
    }

    public void setColor(String color) {
        this.color = color;
    }

    public void saveOrUpdate () throws JSONException {
        SharePHelper sharePHelper = new SharePHelper(Application.getContext());
        // 未存在
        JSONObject json = new JSONObject();
        json.put("name",name);
        json.put("text",text);
        json.put("color",color);
        json.put("time",createTime);
        sharePHelper.push(text,json.toString(), AppConfig.QRCODE_SHAREP_NAME);
    }
    public void copyToClip () {
        Context context = Application.getContext();
        ClipboardManager cbm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
        ClipData clip = ClipData.newPlainText("text",text);
        cbm.setPrimaryClip(clip);
        Toast.makeText(context,"已添加到粘贴板",Toast.LENGTH_SHORT).show();
    }
}
